home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDEject.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  2.3 KB  |  98 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDEject - An XFCN to eject a CD
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDEject.c
  11.     link -sn Main=CDEject -sn STDIO=CDEject ∂
  12.          -sn INTENV=CDEject -rt XFCN=42 ∂
  13.          -m CDEject CDEject.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    AEject(short, short);
  28.  
  29. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  30.  
  31.  
  32. /************************************************************************
  33.  *
  34.  *  Function:        CDEject
  35.  *
  36.  *  Purpose:        eject a disk
  37.  *
  38.  *  Returns:        result of driver calls
  39.  *                    normally 0, but could have parameter error or
  40.  *                    other error
  41.  *
  42.  *  Side Effects:
  43.  *
  44.  *  Description:    Grab the global which contains both refNums.
  45.  *                    extract the two and issue and eject and unmount.
  46.  *
  47.  ************************************************************************/
  48. pascal void
  49. CDEject(paramPtr)
  50. XCmdBlockPtr    paramPtr;
  51. {
  52.     Str31    returnString;
  53.     OSErr    result;
  54.     short    dRefNum;
  55.     short    vRefNum;
  56.     long    bothRefNums;
  57.     Handle    refHandle;
  58.     CntrlParam    myPB;
  59.     
  60.     
  61.     /* Must be no parameters */
  62.     if ((paramPtr->paramCount) != 0)
  63.     {
  64.         /* Report error in parameters by returning -1 */
  65.         NumToStr(paramPtr, (long) -1, &returnString);
  66.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  67.         return;
  68.     }
  69.     
  70.     /* Get the global ioRefNum and convert it. */
  71.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  72.     bothRefNums = atoi(*(refHandle));
  73.     DisposHandle(refHandle);
  74.  
  75.     dRefNum = bothRefNums & 0xFFFF;
  76.     vRefNum = bothRefNums >> 16;
  77.  
  78.     if (vRefNum == 0)
  79.         result = volOffLinErr;
  80.     else
  81.     {
  82.         myPB.ioCompletion = 0;
  83.         myPB.ioNamePtr = nil;
  84.         myPB.ioVRefNum = vRefNum;
  85.         result = PBEject(&myPB);
  86.         if (result == noErr)
  87.             result = PBUnmountVol(&myPB);
  88.     }
  89.     
  90.     /* Convert result to string & return it as error */
  91.     NumToStr(paramPtr, (long) result, &returnString);
  92.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  93. }
  94.  
  95.  
  96. /* C routines for HyperCard callbacks */
  97. #include <XCmdGlue.inc.c>
  98.